home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / stack_language / main.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  3KB  |  183 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 17. Dezember 1992
  4. **
  5. **  This demo shows you how to make gadgets
  6. **
  7. **  with the EGS STACK LANGUAGE. But remember:
  8. **
  9. **  normally you do not need the STACK-LANGUAGE, because you can
  10. **
  11. **  do the same stuff much easier with the egsgadbox.library
  12. **
  13. **  (refer to demo gadget).
  14. **
  15. **
  16. **
  17. **  In these files you will find some useful routines
  18. **  for opening and closing Libraries and error handling
  19. **
  20. **  (c) by VIONA-Development
  21. **
  22. */
  23.  
  24. #include "includes.c"
  25. #include "Global.h"
  26. #include "stack-language.c"
  27. #include "Eventloop.c"
  28. #include "InitMenu.c"
  29.  
  30. BOOL InitLibraries(struct OpenStructTyp *);
  31. void CloseLibraries(struct OpenStructTyp *);
  32.  
  33.  
  34. /*
  35. **  Opens the libs from the OpenStructTyp
  36. **  (see global.h)
  37. **
  38. */
  39.  
  40. BOOL InitLibraries(struct OpenStructTyp *OS)
  41. {
  42.  struct OpenStructTyp *p = &OS[0];
  43.  
  44.  while (p->Ort != NULL)
  45.  {
  46.    if ((*(p->Ort) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  47.        {
  48.            printf(" Can't open %s version %d",p->Name, p->Version);
  49.            return FALSE;
  50.        }
  51.        else
  52.        {  p ++; }
  53.  }
  54.    return TRUE;
  55. }
  56.  
  57.  
  58. /*
  59. ** Close the Libs from the OpenStructTyp
  60. **
  61. */
  62. void CloseLibraries(struct OpenStructTyp *OS)
  63. {
  64.  struct OpenStructTyp *p = &OS[0];
  65.  
  66.  while (*(p->Ort) != NULL && p->Name != NULL)
  67.  {
  68.         CloseLibrary((void *)(*(p->Ort)));
  69.         *(p->Ort) = NULL;
  70.         p++;
  71.  }
  72. }
  73. /**/
  74.  
  75.  
  76. /*
  77. ** This routine is for error handling.
  78. ** It closes all open things of the
  79. ** program.
  80. **
  81. */
  82. void myError(char *string)
  83. {
  84.   if ( string != NULL)
  85.   {
  86.       if ( EGSRequestBase == NULL )
  87.       {
  88.           printf("%s\n",string);
  89.  
  90.       }else{
  91.  
  92.          ErrorReq = (ER_SimpleRequestPtr)ER_CreateSimpleRequest(NULL,
  93.                                           (char *)string,(char *)"OK");
  94.  
  95.  
  96.  
  97.          /*
  98.      **  Open requester in the middle of the screen,
  99.          **
  100.      **  if you can!
  101.          */
  102.  
  103.          ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  104.  
  105.          ER_DoRequest(&(ErrorReq->Req)) ;
  106.       }
  107.   }
  108.  
  109.   if (Window)
  110.   {
  111.  
  112.   ErrorReq = ER_CreateSimpleRequest(NULL,
  113.                 "Hello world !|This is a Requester !","OK");
  114.  
  115.   ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  116.  
  117.   ER_DoRequest(&(ErrorReq->Req)) ;
  118.   }
  119.  
  120.   if ( FontforMenu )
  121.     EG_CloseFont(FontforMenu);
  122.  
  123.   if ( Window )
  124.     EI_CloseWindow(Window);
  125.  
  126.   if ( Menu )
  127.     EI_FreeMenu(Menu);
  128.  
  129.  if ( ErrorReq )
  130.      ER_DeleteRequest(&(ErrorReq->Req));
  131.  
  132.   CloseLibraries(OpenStruct);
  133.  
  134.  exit(0);
  135.  
  136.  
  137. }
  138. /**/
  139.  
  140. int main(int argc, char *argv[])
  141. {
  142.  
  143.   if (argc == 2 && strcmp("?",argv[1]) == 0)
  144.    {
  145.     printf("Aufruf: %s\n  Markus van Kempen 12 Nov 1992",argv[0]);
  146.  
  147.    }else
  148.    {
  149.  
  150.       if ( InitLibraries(OpenStruct) == FALSE)
  151.           myError("Can't OpenLibrary");
  152.  
  153.       FontforMenu = (EG_EFontPtr)EG_OpenFont((struct TextAttr *)&FontStr);
  154.  
  155.       if ( FontforMenu == NULL )
  156.           myError("Could not open font");
  157.  
  158.         Menu=InitMenu(FontforMenu);
  159.  
  160.       if ( Menu == NULL )
  161.       myError("Could not build menu");
  162.  
  163.       newwin.FirstGadgets=(struct EI_Gadget *)&myBoolGadget;
  164.       newwin.Menu=Menu;
  165.       newwin.Title=argv[0];
  166.  
  167.       Window = (EI_WindowPtr)EI_OpenWindow ((struct EI_NewWindow *)&newwin);
  168.  
  169.      if (Window)
  170.        {
  171.  
  172.         HandleEvents(Window);
  173.  
  174.         }else{
  175.                myError("Could not open window");
  176.        }
  177.    }
  178.   myError(NULL);
  179. }
  180.  
  181.  
  182.  
  183.